const path = require('path')

function resolve (dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  chainWebpack: config => {
    config.resolve.alias
      .set('@', resolve('src'))
      .set('js', resolve('src/assets/js'))
      .set('css', resolve('src/assets/css'))
      .set('img', resolve('src/assets/img'))
      .set('public', resolve('src/components/public'))
  },
  // 如果你不需要生产环境的 source map，可以将其设置为 false 以加速生产环境构建
  productionSourceMap: false,
  devServer: {
    port: 8080,
    open: true, // 是否自动打开浏览器页面
    proxy: {
      '/api': {
        // 要访问的跨域的域名
        target: 'http://localhost:8081/',
        ws: true,
        changeOrigin: true, // 是否跨域
        pathRewrite: {
          '^/api': '/api'
        }
      }
    }
  }
}
